package com.ljp.chat.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.ljp.chat.entity.pojo.Account;
import com.ljp.chat.mapper.AccountMapper;
import com.ljp.chat.service.AccountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ljp.chat.support.expansion.service.UniqueCheck;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author LvJunPeng
 * @since 2022-11-02
 */
@Service
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> implements AccountService {

    @Override
    public String login(String account, String password) {
        Account queryAccount = this.lambdaQuery().eq(Account::getAccount, account).one();
        if (queryAccount.getPassword().equals(password)) {
            StpUtil.login(queryAccount.getId());
            return "登陆成功";
        }
        return "登陆失败";
    }

    @Override
    public boolean updateAccount(Account account) throws Exception {
        UniqueCheck.uniqueCheck(account, UniqueCheck.UPDATE, "is_delete");
        return this.updateById(account);
    }
}
